package com.zgh.opcua.config;

import com.zgh.opcua.SpringContextHolder;
import org.springframework.util.StringUtils;

/**
 * @ClassName OpcContext
 * @Description opc连接信息
 * @Author Administrator
 * @Date 15:03 2025/10/31
 * @Version 1.0
 */
@SuppressWarnings({"unused", "UnusedReturnValue", "SameParameterValue", "DuplicatedCode", "JavadocLinkAsPlainText"})
public class OpcContext {

    private static String endpointUrl;

    private static String security;

    private static String idpUsername;

    private static String idpPassword;

    //保存数据的队列长度
    private static Integer queueCapacity;
    //批量保存数量
    private static Integer batchSize;
    //最大等待时间（毫秒）
    private static Integer flushIntervalMs;
    //队列拉取超时
    private static Integer pollTimeoutMs;
    //写入队列超时
    private static Integer offerTimeoutMs;

    public static String getEndpointUrl() {
        if (StringUtils.isEmpty(endpointUrl)) {
            OPCProperties opcProperties = SpringContextHolder.getBean(OPCProperties.class);
            endpointUrl = opcProperties.getEndpointUrl();
        }
        return endpointUrl;
    }

    public static String getSecurity() {
        if (StringUtils.isEmpty(security)) {
            OPCProperties opcProperties = SpringContextHolder.getBean(OPCProperties.class);
            security = opcProperties.getSecurity();
        }
        return security;
    }

    public static String getIdpUsername() {
        if (StringUtils.isEmpty(idpUsername)) {
            OPCProperties opcProperties = SpringContextHolder.getBean(OPCProperties.class);

            idpUsername = opcProperties.getIdpUsername();
        }
        return idpUsername;
    }

    public static String getIdpPassword() {
        if (StringUtils.isEmpty(idpPassword)) {
            OPCProperties opcProperties = SpringContextHolder.getBean(OPCProperties.class);
            idpPassword = opcProperties.getIdpPassword();
        }
        return idpPassword;
    }

    public static Integer getQueueCapacity() {
        if (StringUtils.isEmpty(queueCapacity)) {
            OPCProperties opcProperties = SpringContextHolder.getBean(OPCProperties.class);
            queueCapacity = opcProperties.getQueueCapacity();
        }
        return queueCapacity;
    }

    public static Integer getBatchSize() {
        if (StringUtils.isEmpty(batchSize)) {
            OPCProperties opcProperties = SpringContextHolder.getBean(OPCProperties.class);
            batchSize = opcProperties.getBatchSize();
        }
        return batchSize;
    }

    public static Integer getFlushIntervalMs() {
        if (StringUtils.isEmpty(flushIntervalMs)) {
            OPCProperties opcProperties = SpringContextHolder.getBean(OPCProperties.class);
            flushIntervalMs = opcProperties.getFlushIntervalMs();
        }
        return flushIntervalMs;
    }

    public static Integer getPollTimeoutMs() {
        if (StringUtils.isEmpty(pollTimeoutMs)) {
            OPCProperties opcProperties = SpringContextHolder.getBean(OPCProperties.class);
            pollTimeoutMs = opcProperties.getPollTimeoutMs();
        }
        return pollTimeoutMs;
    }

    public static Integer getOfferTimeoutMs() {
        if (StringUtils.isEmpty(offerTimeoutMs)) {
            OPCProperties opcProperties = SpringContextHolder.getBean(OPCProperties.class);
            offerTimeoutMs = opcProperties.getOfferTimeoutMs();
        }
        return offerTimeoutMs;
    }

    public static void setSecurity(String security) {
        OpcContext.security = security;
    }

    public static void setEndpointUrl(String serverUrl) {
        OpcContext.endpointUrl = serverUrl;
    }

    public static void setIdpUsername(String username) {
        OpcContext.idpUsername = username;
    }

    public static void setIdpPassword(String password) {
        OpcContext.idpPassword = password;
    }

    public static void setQueueCapacity(Integer queueCapacity) {
        OpcContext.queueCapacity = queueCapacity;
    }

    public static void setBatchSize(Integer batchSize) {
        OpcContext.batchSize = batchSize;
    }

    public static void setFlushIntervalMs(Integer flushIntervalMs) {
        OpcContext.flushIntervalMs = flushIntervalMs;
    }

    public static void setPollTimeoutMs(Integer pollTimeoutMs) {
        OpcContext.pollTimeoutMs = pollTimeoutMs;
    }

    public static void setOfferTimeoutMs(Integer offerTimeoutMs) {
        OpcContext.offerTimeoutMs = offerTimeoutMs;
    }
}
